﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.IO;
using BlueMonkey.BlueCore;

namespace BlueMonkey.View
{
    /// <summary>
    /// Interaction logic for WindowVDO.xaml
    /// </summary>
    public partial class WindowVDO : Window
    {
        public WindowVDO()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(WindowVDO_Loaded);
            this.Closing += new System.ComponentModel.CancelEventHandler(WindowVDO_Closing);
            videoPlayer1.OnShowMenu += new EventHandler(videoPlayer1_OnShowMenu);
            videoPlayer1.OnHideMenu += new EventHandler(videoPlayer1_OnHideMenu);
            videoPlayer1.OnStop += new EventHandler(videoPlayer1_OnStop);
        }

        void videoPlayer1_OnStop(object sender, EventArgs e)
        {
            this.Close();
            //throw new NotImplementedException();
        }

        void WindowVDO_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            videoPlayer1.Stop();
            //throw new NotImplementedException();
        }

        void videoPlayer1_OnHideMenu(object sender, EventArgs e)
        {
            GridLength len = new GridLength(0);
            topmenu.Height = len;
            //throw new NotImplementedException();
        }

        void videoPlayer1_OnShowMenu(object sender, EventArgs e)
        {
            GridLength len = new GridLength(30);
            topmenu.Height = len;
            //throw new NotImplementedException();
        }

        void WindowVDO_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_media != null)
                {
                    videoPlayer1.Media = _media;
                    Title.Text = _media.Title;
                }
            }
            catch 
            {
                //prevent exception on design mode.
            }
        }

        private MediaObject _media = null;

        public MediaObject Media
        {
            get { return _media; }
            set { _media = value; }
        }

        private void imgClose_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }

        private void StackPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton == MouseButton.Left)
                    this.DragMove();
            }
            catch { }
        }

        private void imgMinimize_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = System.Windows.WindowState.Minimized;
        }

        private void imgMaximize_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (this.WindowState == System.Windows.WindowState.Maximized)
            {
                this.WindowState = System.Windows.WindowState.Normal;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
        }
    }
}
